package com.ssy.lingxi.member.merchant.controller.paas;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.PlatformProcessRuleVO;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.RoleAuthVO;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.RoleConfigVO;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.RoleVO;
import com.ssy.lingxi.member.merchant.service.paas.IPaasPlatformProcessService;
import com.ssy.lingxi.member.merchant.service.paas.IPaasRoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 系统初始化 - 会员角色管理接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-13
 */
@RestController
@RequestMapping("/paas/role")
public class RoleController {
    @Resource
    private IPaasRoleService roleService;

    @Resource
    private IPaasPlatformProcessService platformProcessService;

    /**
     * 新增角色
     * @param roleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Wrapper<Long> addRole(@RequestBody @Validated(RoleVO.Add.class) RoleVO roleVO) {
        return roleService.addRole(roleVO);
    }

    /**
     * 更新角色
     * @param roleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> updateRole(@RequestBody @Validated(RoleVO.Update.class) RoleVO roleVO) {
        return roleService.updateRole(roleVO);
    }

    /**
     * 更改角色状态
     * @param roleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/status", method = RequestMethod.POST)
    public Wrapper<Void> updateRoleStatus(@RequestBody @Validated(RoleVO.UpdateStatus.class) RoleVO roleVO) {
        return roleService.updateRoleStatus(roleVO);
    }

    /**
     * 删除角色
     * @param roleVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper<Void> deleteRole(@RequestBody @Validated(RoleVO.Delete.class) RoleVO roleVO) {
        return roleService.deleteRole(roleVO);
    }

    /**
     * 设置角色权限
     * @param roleAuthVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/set/auth", method = RequestMethod.POST)
    public Wrapper<Void> setRoleAuth(@RequestBody @Valid RoleAuthVO roleAuthVO) {
        return roleService.setRoleAuth(roleAuthVO);
    }

    /**
     * 设置（新增、修改、删除）角色关联的会员配置资料
     * @param configVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/set/config", method = RequestMethod.POST)
    public Wrapper<Void> setRoleConfig(@RequestBody @Valid RoleConfigVO configVO) {
        return roleService.setRoleConfig(configVO);
    }

    /**
     * 新增或修改角色关联的平台会员审核流程
     * @param platformProcessVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/set/process", method = RequestMethod.POST)
    public Wrapper<Void> insertOrUpdateBasePlatformProcess(@RequestBody @Valid PlatformProcessRuleVO platformProcessVO) {
        return platformProcessService.insertOrUpdateBasePlatformProcess(platformProcessVO);
    }
}
